package com.cetc.testkafka.kafkaproducer;

import com.cetc.testkafka.common.TopicConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * kafka生产者测试
 */
@Component
public class SimpleKafkaProducer<T> {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    // 发送消息
    public void sendMessage(String topic, String body) {
        kafkaTemplate.send(topic,body);
    }

    public void sendMessage(String topic, T body) {
        //String jsonObj = JSON.toJSONString(obj);
        String bodystr = body.toString();
        sendMessage(topic, bodystr);
    }

}
